package com.simple.elpmobile.onlinecase.utils;


import com.simple.elpmobile.onlinecase.engine.AppEngine;

import android.content.Context;
import android.content.SharedPreferences;



public abstract class PreferencesUtil
{

    private static SharedPreferences mSharePreferences;

    private static final String CONFIG_FILE_NAME = "englishweekly_config";	
    
    /**
     * app版本
     */
    public static final String KEY_VERSION = "key_Version";
    
    /**
     * 用户登录相关
     */
    public static final String KEY_LOGIN_TYPE = "key_loginType";
    
    public static final String KEY_USER_MAIL = "key_userMail";
    
    public static final String KEY_USER_PWD = "key_userPwd";
    
    public static final String KEY_USER_OPENID = "key_userOpenId";
    
    public static final String KEY_USER_FIRST = "key_userFirst";
    
    public static final String KEY_HTML_MODEL_VERSION = "key_htmlModelVersion";
    
    
    /**
     * 保存用户的信息，防止崩溃后，无法拿到用户信息
     */
    public static final String KEY_USER_NICK = "key_userNick";
    public static final String KEY_USER_GENDER = "key_userGender";
    public static final String KEY_USER_BIRTH= "key_userBirth";
    public static final String KEY_USER_HEAD = "key_userHead";
    
    
    /**
     * 用户选择的报纸信息
     */
    public static final String KEY_AREA_SELECTED = "key_areaSelected";
    
    public static final String KEY_GRADE_SELECTED = "key_gradeSelected";
    
    public static final String KEY_PUBLISH_SELECTED = "key_publishSelected";
    
    
    /**
     * 密码保存显示
     */
    public static final String KEY_LAST_SAVED_PWD = "key_savedPwdLastTime";
    
    /**
     * 用户引导
     */
   public static final String KEY_IS_FIRST_USE_LISTEN = "key_firstUseListen";
   public static final String KEY_IS_FIRST_USE_ORAL_EXERCISE = "key_firstUseOralExercise";
   public static final String KEY_IS_FIRST_SHOW_ORAL_EXERCISE_SCORES = "key_firstShowOralExerciseScores";
   public static final String KEY_IS_FIRST_USE_DIALOG_TEST = "key_firstUseDialogTest";
   public static final String KEY_IS_FIRST_USE_PARAGRAPH_TEST = "key_firstUseParaphTest";
   public static final String KEY_IS_FIRST_USE_COLLECTION = "key_firstUseCollection";
    /**
     * wifi更新
     */
    public static final String KEY_WIFI_UPDATE = "key_wifi_update";
    
    
    public static final String KEY_ALERT_IN_UNWIFI = "alert_in_unwifi";
    
    /**
     * 未登录下使用一次练习
     */
    public static final String KEY_NOLOGIN_USE = "key_nologin_use";
    /**
     * 是否已生成二维码桌面图标
     */
    public static final String KEY_BARCODE_ICON_GENERATED = "key_barcode_icon_generated";
    
    
    private synchronized static SharedPreferences preferences()
    {
        if (mSharePreferences == null)
        {
            mSharePreferences = AppEngine.getInstance().getContext().getSharedPreferences(
                    CONFIG_FILE_NAME, Context.MODE_PRIVATE);
        }
        return mSharePreferences;

    }

    public static String getString(String key, String defValue)
    {
        return preferences().getString(key, defValue);
    }

    public static int getInt(String key, int defValue)
    {
        return preferences().getInt(key, defValue);
    }

    public static long getLong(String key, long defValue)
    {
        return preferences().getLong(key, defValue);
    }

    public static boolean getBoolean(String key, boolean defValue)
    {
        return preferences().getBoolean(key, defValue);
    }

    public static boolean commit(String key, int value)
    {
        return preferences().edit().putInt(key, value).commit();
    }

    public static boolean commit(String key, String value)
    {
        return preferences().edit().putString(key, value).commit();
    }

    public static boolean commit(String key, long value)
    {
        return preferences().edit().putLong(key, value).commit();
    }

    public static boolean commit(String key, Boolean value)
    {
        return preferences().edit().putBoolean(key, value).commit();
    }

}
